<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            text-align: center;
        }

        .button {
            width: 0;
            height: 0;
            border: 10px solid;
            position: absolute;
        }

        .btn1 {
            border-color: black transparent transparent transparent;
            left: 100px;
            top: 20px;
        }

        .btn2 {
            border-color: transparent transparent black transparent;
            right: 100px;
            top: 10px;

        }

        p {
            height: 50px;
            line-height: 50px;
        }

        .box {
            width: 500px;
            margin: 0 auto;
            position: relative;
        }

        ul {
            display: flex;
            justify-content: left;
            list-style: none;
            flex-wrap: wrap
        }

        .date li {
            width: 70px;
            line-height: 30px;
        }

        .today {
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="btn1 button"></div>
        <p></p>
        <div class="btn2 button"></div>
        <div class="date">
            <ul>
                <li>星期日</li>
                <li>星期一</li>
                <li>星期二</li>
                <li>星期三</li>
                <li>星期四</li>
                <li>星期五</li>
                <li>星期六</li>
            </ul>
            <ul class="day">

            </ul>
        </div>
    </div>

    <script>
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let ul = document.querySelector('.day')
        let btn1 = document.querySelector('.btn1')
        let btn2 = document.querySelector('.btn2')
        //初始化
        function init() {
            ul.innerHTML = ''
            let fisrtDay = new Date(year, month - 1, 1).getDay();
            let days = new Date(year, month, 0).getDate();
            document.querySelector('p').innerHTML = `${year}年${month}月`
            for (let i = 0; i < fisrtDay; i++) {
                let li = document.createElement('li')
                ul.appendChild(li)
            }
            for (let i = 1; i <= days; i++) {
                let li = document.createElement('li')
                li.innerHTML = i + '日'
                ul.appendChild(li)
            }
        }
        init();
        btn1.onclick = () => {
            month--
            if (month == 0) {
                month = 12
                year--
            }
            init();
        }
        btn2.onclick = () => {
            month++
            if (month == 13) {
                month = 1
                year++
            }
            init();
        }
    </script>
</body>

</html>